{include file="common/head"/}
<div class="layui-page-header headers">
    <div class="pagewrap">
        <span class="layui-breadcrumb">
          <a href="{:url('index/index')}">首页</a>
          <a href="javascript:;">{$authruleinfo.pid}</a>
          <a><cite>{$authruleinfo.id}</cite></a>
        </span>
        <a href="javascript:location.replace(location.href);" style="float:right" class="layui-btn layui-btn-blue refreshs"><i class="fa fa-history falocation" aria-hidden="true"></i>
        </a>
    </div>
</div>
<div class="layui-row layui-rows">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="demoTable">
                <div class="layui-inline layui-inlines">
                    <input class="layui-input"  id="starttime" placeholder="请输入开始时间">
                </div>
                <div class="layui-inline layui-inlines">
                    <input class="layui-input"  id="endtime" placeholder="请输入结束时间">
                </div>
                <div class="layui-inline layui-inlines">
                    <input class="layui-input" name="key" id="key" placeholder="请输入查询内容">
                </div>
                <button class="layui-btn layui-btns layui-btn-blue" id="search" data-type="reload">
                    <i class="layui-icon" style="color: #fff">&#xe615;</i>搜索
                </button>
                {if condition="input('get.id')"}
                <input type="hidden" value="{:input('get.id')}" id="groupid">
                <button class="layui-btn layui-btns layui-btn-green" id="group">
                    <i class="fa fa-object-group" aria-hidden="true"></i>
                    分组
                </button>
                {else /}
                {if condition="!(input('get.ids'))"}
                <button class="layui-btn layui-btns layui-btn-green" id="groups" >
                    <i class="fa fa-object-group" aria-hidden="true"></i>
                    分组
                </button>
                {/if}
                {/if}

                <button  tipsmsg="删除" class="layui-btn layui-btns layui-btn-red onmousemovebtns" id="delAll">
                    <i class="layui-icon">&#xe640;</i>删除
                </button>
            </div>
            <table class="layui-table" id="list" lay-filter="list"></table>
        </div>
    </div>
</div>
<div class="headalert" id="test" style="display: none;"><br>
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">分组</label>
            <div class="layui-input-inline">
                <select name="id">
                    <option value="">请选择分组</option>
                    {volist name="group" id="vo"}
                    <option value="{$vo.id}">{$vo.name}</option>
                    {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn layui-btns layui-btn-blue" lay-submit="" lay-filter="commentinggroup">分组</button>
                <button type="reset" class="layui-btn layui-btns layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<input type="hidden" value="{:input('get.ids')}" id="ids">
{include file="common/foot"/}
<!--<script type="text/html" id="topBtn">
    <button tipsmsg="添加" class="layui-btn layui-btn layui-btn-blue layui-btn-sm onmousemovebtns"
            onclick="x_admin_show('添加评论','{:url('commentadd')}','700px','650px','95%','95%')">
        <i class="layui-icon"></i>添加
    </button>
</script>-->
<script type="text/html" id="topBtn">
    <button tipsmsg="添加" class="layui-btn layui-btn layui-btn-blue layui-btn-sm onmousemovebtns"
            onclick="x_admin_show('添加评论','{:url('commentadd')}','600px','300px','95%','55%')">
        <i class="layui-icon"></i>添加
    </button>
</script>
<script type="text/html" id="action" >

    <a tipsmsg="编辑" class="layuimsg"
       onclick="x_admin_show('编辑评论信息','{:url('commentedit')}?id={{d.id}}','600px','300px','95%','55%')">
        <button class="layui-btn layui-btn-blue layui-btn-xs layui-btns">
            <i class="layui-icon">&#xe642;</i>
        </button>
    </a>
    <a lay-event="del" tipsmidssg="删除" class="layuimsg">
    <button class="layui-btn layui-btn-red layui-btn-xs layui-btns">
      <i class="layui-icon">&#xe640;</i>
    </button>
    </a>

</script>
<script>
    var ids = $("#ids").val();
    var groups = "";
    layui.use(['table','form','element','laydate'], function() {
        var table = layui.table,form = layui.form,element = layui.element,laydate = layui.laydate, $ = layui.jquery;
        var tableIn = table.render({
            elem: '#list',
            url: '{:url("commentlist")}',
            text:{none: '<i class="fa fa-snowflake-o" aria-hidden="true"></i>&nbsp;暂无相关数据'},
            method: 'post',
            toolbar: '#topBtn',
            where:{id:ids},
            page: true,
            limits:[10,50,100,200,300,400,500,1000,2000,3000,4000],
            cols: [[
                {checkbox:true,width: 80},
                {field: 'id', title: '编号', width: 120,align: 'center',sort:true},
                {field: 'aid', title: '操作用户',width:150,align: 'center'},
                {field: 'content', title: '内容',width:300},
                {field: 'addtime', title: '操作时间',align: 'center',width:170,sort:true},
                {width: 120,title: '操作', align: 'center', toolbar: '#action'}
            ]],
            limit: 10, //每页默认显示的数量
            done:function(msg){
                onmousemoves();
               /* console.log(msg.data);*/
            }
        });

        //复选框选中的个数
        table.on('checkbox(list)', function (obj) {
            var checkStatus = table.checkStatus('list');
            var data = checkStatus.data;
            layer.msg('选中了：'+ data.length + ' 个');
        });

        laydate.render({
            elem: '#starttime'
            ,theme: '#4476A7'
            ,max: 'new Date()'
        });

        laydate.render({
            elem: '#endtime'
            ,theme: '#4476A7'
            ,max: 1
        });

        //搜索
        $('#search').on('click', function() {
            var key = $('#key').val();
            var starttime = $("#starttime").val();
            var endtime = $("#endtime").val();
            var t1 = new Date(starttime);
            var t2 = new Date(endtime);
            if((t2 - t1) < 0){
                layer.msg('时间范围选择错误！');
                return false;
            }
            if($.trim(key) == '' && starttime == "" && endtime == "") {
                layer.msg('搜索内容不能为空！');
                return false;
            }
            tableIn.reload({
                where: {key: key,starttime:starttime,endtime:endtime}
            })
        });

        //分组
        $('#group').click(function(){
            var checkStatus = table.checkStatus('list'); //test即为参数uid设定的值
            var id = [];
            $(checkStatus.data).each(function (i, o) {
                id.push(o.id);
            });
            if (id == ""){
                layer.msg("请选择评论进行分组！");
                return false;
            }
            cid = id.toString();
            var id = $("#groupid").val();
            $.post("{:url('commentinggroup')}",{cid:cid,id:id},function(res){
                if(res.code == 1){
                    layer.msg(res.msg);
                    setTimeout(function(){
                        window.parent.location.reload();//修改成功后刷新父界面
                    }, 1000);
                }else if(res.code === 0) {
                    layer.msg(res.msg);
                }else{
                    layer.msg('你无操作权限！');
                }
            },'json')
            return false;
        })

        //分组
        $('#groups').click(function(){
            var checkStatus = table.checkStatus('list'); //test即为参数uid设定的值
            var id = [];
            $(checkStatus.data).each(function (i, o) {
                id.push(o.id);
            });
            if (id == ""){
                layer.msg("请选择评论进行分组！");
                return false;
            }
            groups = id.toString();
            layer.open({
                type: 1,
                title: '加入分组',
                skin: 'layui-layer-lan',
                shadeClose: true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                shade:0.4,
                anim: 1,
                area: screen() <2 ? ['95%','75%'] : ['400px', '400px'],
                content: $("#test").html()
            });
            form.render();
        })

        //监听提交
        form.on('submit(commentinggroup)', function(data){
            data.field.cid = groups;
            if(data.field.id == ""){
                layer.msg("请选择分组信息!");
                return false;
            }
            $.post("{:url('commentinggroup')}",data.field,function(res){
                if(res.code == 1){
                    layer.msg(res.msg);
                    setTimeout(function(){
                        window.parent.location.reload();//修改成功后刷新父界面
                    }, 1000);
                }else if(res.code === 0) {
                    layer.msg(res.msg);
                }else{
                    layer.msg('你无操作权限！');
                }
            },'json')
            return false;
        });


        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('您确定要删除该信息吗？', {icon: 3,skin: 'layui-layer-lan',anim: 4,title:'删除'}, function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('commentdel')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg);
                            tableIn.reload();
                        }else if(res.code === 0) {
                            layer.msg(res.msg);
                        }else{
                            layer.msg('你无操作权限！');
                        }
                    },'json');
                    layer.close(index);
                });
            }
        });

        $('#delAll').click(function(){
            var checkStatus = table.checkStatus('list'); //test即为参数uid设定的值
            var id = [];
            $(checkStatus.data).each(function (i, o) {
                id.push(o.id);
            });
            if (id == ""){
                layer.msg("请选择内容进行删除");
                return false;
            }
            layer.confirm('确认要删除选中信息吗？', {icon: 3,skin: 'layui-layer-lan',anim: 4,title:'删除'}, function(index) {
                layer.close(index);
                var loading = layer.load(1, {shade: [0.1, '#fff']});
                $.post("{:url('commentdel')}", {id: id}, function (data) {
                    layer.close(loading);
                    if (data.code === 1) {
                        layer.msg(data.msg);
                        tableIn.reload();
                    }else if(data.code === 0) {
                        layer.msg(data.msg);
                    }else{
                        layer.msg('你无操作权限！');
                    }
                },'json');
            });
        })
    });
</script>
